package com.shixj.demo.latch;

import java.util.concurrent.CountDownLatch;

/**
 * Created by shixj on 2017/9/25.
 * 控制开始
 */
public class LatchSwitch implements Runnable {
    private int beginIndex;
    private final CountDownLatch startSignal;

    public LatchSwitch(int beginIndex, CountDownLatch startSignal) {
        this.beginIndex = beginIndex;
        this.startSignal = startSignal;
    }

    @Override
    public void run() {
        try {
            startSignal.await(); //等待开始执行信号的发布
            System.out.println("线程"+beginIndex+"开始执行");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
